//package com.haoze.nurseapp.schedule;
//
//import com.haoze.common.model.TaskExecuteBatchEntity;
//import com.haoze.common.utils.DateUtil;
//import com.haoze.nurseapp.dao.StaticCenterMapper;
//import com.haoze.nurseapp.dao.TaskExecuteBatchMapper;
//import com.haoze.nurseapp.dao.TaskExecuteDetailMapper;
//import com.haoze.nurseapp.dao.TaskExecuteMapper;
//import com.haoze.nurseapp.model.StaticCenterEntity;
//import com.haoze.nurseapp.model.TaskExecuteDetailEntity;
//import com.haoze.nurseapp.model.TaskExecuteEntity;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//import org.springframework.transaction.annotation.Transactional;
//
//import javax.annotation.Resource;
//import java.text.SimpleDateFormat;
//import java.util.Date;
//import java.util.List;
//
//@Component
//@ConditionalOnProperty(prefix = "schedule", name = "match", havingValue = "true")
//public class MatchSchedule {
//
//    @Resource
//    TaskExecuteMapper taskExecuteMapper;
//
//    @Resource
//    StaticCenterMapper staticCenterMapper;
//
//    @Resource
//    TaskExecuteDetailMapper taskExecuteDetailMapper;
//
//    @Resource
//    TaskExecuteBatchMapper taskExecuteBatchMapper;
//
//    /**
//     * 每5分钟同步静配中心配置数据
//     */
//    @Scheduled(fixedDelay = 1000*60)
////    @Scheduled(initialDelay = 1000, fixedRate = 5000000)
//    @Transactional(rollbackFor = Exception.class)
//    public void matchData(){
//        System.out.println("MatchSchedule did at "+new Date().getTime());
//        //定义是一个当天时间
//        Date date = new Date();
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//        String currentDate = sdf.format(date);
//        //获取当前任务表中未匹配barcode的当天需要执行的数据
//        List<TaskExecuteBatchEntity> taskExecuteEntityList = taskExecuteMapper.queryTaskInfo(currentDate, "TASK_INFUSION");
//        for (int i = 0; i < taskExecuteEntityList.size(); i++) {
//            TaskExecuteBatchEntity taskExecuteBatchEntity = taskExecuteEntityList.get(i);
//            String orderNo = taskExecuteMapper.queryorderNo(taskExecuteBatchEntity.getInpatorderdataId());
//            TaskExecuteEntity taskExecuteEntity = taskExecuteMapper.selectByPrimaryKey(taskExecuteBatchEntity.getTaskExecuteId());
//            String useTime = DateUtil.dateToString(taskExecuteBatchEntity.getStartDatetime(), "HH:mm");
//            StaticCenterEntity staticCenterEntity = staticCenterMapper.queryInfo(taskExecuteEntity.getInpatNum(), orderNo, currentDate, useTime);
//            if (staticCenterEntity != null) {
//                taskExecuteBatchEntity.setBarCode(staticCenterEntity.getBarCode());
//                staticCenterEntity.setStatus("1");
//                taskExecuteDetailMapper.updateByTaskExecuteId(staticCenterEntity.getBarCode(), taskExecuteBatchEntity.getTaskBatchId());
//                taskExecuteBatchMapper.updateByPrimaryKeySelective(taskExecuteBatchEntity);
//                staticCenterMapper.updateByPrimaryKeySelective(staticCenterEntity);
//            }
//        }
//    }
//
//}
